#include <head.h>
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        printf("./app filename\n");
        return -1;
    }
    int fd = open(argv[1], O_RDWR);
    int fd2 = open("temp.txt", O_RDWR);
    OPEN_ERR(fd);
    OPEN_ERR(fd2);
    char buf = 'A';
    int i = 10;
    int ret = 10;
    // 开锁
    flock(fd, LOCK_EX); // 排它锁
    read(fd2, &ret, 1);
    lseek(fd, 0, SEEK_END);
    while (i--)
    {
        write(fd, &buf, 1);
        sleep(1);
    }
    ret = lseek(fd, 0, SEEK_CUR);
    lseek(fd2, 0, SEEK_SET);
    write(fd2, &ret, sizeof(int)); // 写入文件大小
    // 解锁
    flock(fd, LOCK_UN);
    close(fd);
    close(fd2);
    return 0;
}